#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi

#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > rsp_soppaccexci.info <<%EOF%
   rsp_soppaccexci
   ---------------
   Molecule:         H2O
   Wave Function:    CCSD (SOPPA(CCSD)) / cc-pVDZ
   Test Purpose:     SOPPA(CCSD) Singlet excitation energies
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > rsp_soppaccexci.mol <<%EOF%
BASIS
cc-pVDZ
SOPPA(CCSD) calculation of singlet excitation energies. Symmetry

    2    2  X  Z
        8.    1
O     0.0 -0.2249058930 0.0
        1.    1
H     1.45235 0.899623 0.0
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > rsp_soppaccexci.dal <<%EOF%
**DALTON INPUT
.RUN RESPONSE
**WAVE FUNCTION
.HF
.CC
*CC INPUT
.SOPPA(CCSD)
**RESPONSE
.SOPPA(CCSD)
*LINEAR
.SINGLE RESIDUE
.DIPLEN
.ROOTS
 2 2 2 2
**END OF DALTON INPUT
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >rsp_soppaccexci.check
cat >>rsp_soppaccexci.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# Basis set
CRIT1=`$GREP "O * 1 * 8\.0000 * 26 * 14 * \[9s4p1d\|3s2p1d\]" $log | wc -l`
CRIT2=`$GREP "H * 2 * 1\.0000 * 7 * 5 * \[4s1p\|2s1p\]" $log | wc -l`
CRIT3=`$GREP "total\: * 3 * 10\.0000 * 40 * 24" $log | wc -l`
CRIT4=`$GREP "Spherical harmonic basis used\." $log | wc -l`
TEST[1]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[1]=4
ERROR[1]="BASIS SET NOT READ CORRECTLY"

# Geometry
CRIT1=`$GREP "Total number of coordinates\: * 9" $log | wc -l`
CRIT2=`$GREP "1 * x * (0| )\.0000000000" $log | wc -l`
CRIT3=`$GREP "2 * y * (\-0|\-)\.2249058930" $log | wc -l`
CRIT4=`$GREP "3 * z * (0| )\.0000000000" $log | wc -l`
CRIT5=`$GREP "4 * x * 1\.4523500000" $log | wc -l`
CRIT6=`$GREP "5 * y * (0| )\.8996230000" $log | wc -l`
CRIT7=`$GREP "6 * z * (0| )\.0000000000" $log | wc -l`
CRIT8=`$GREP "7 * x * \-1\.4523500000" $log | wc -l`
CRIT9=`$GREP "8 * y * (0| )\.8996230000" $log | wc -l`
CRIT10=`$GREP "9 * z * (0| )\.0000000000" $log | wc -l`
TEST[2]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ \
		$CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT10`
CTRL[2]=10
ERROR[2]="GEOMETRY NOT READ CORRECTLY"

# Energies
CRIT1=`$GREP "Total SCF   energy\: * \-76\.025681483" $log | wc -l`
CRIT2=`$GREP "Total MP2   energy\: * \-76\.2306668" $log | wc -l`
CRIT3=`$GREP "Total CCSD  energy\: * \-76\.2400019" $log | wc -l`
TEST[3]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[3]=6
ERROR[3]="ENERGIES NOT CORRECT"

# Response setup
CRIT1=`$GREP "SOPPA\(CCSD\) \: * Second Order Polarization Propagator Approximation" $log | wc -l`
CRIT2=`$GREP "2 Excitation energies are calculated for symmetry no\. * [1-4]" $log | wc -l`
CRIT3=`$GREP "1 property residues are calculated with labels\:" $log | wc -l`
TEST[4]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3`
CTRL[4]=8
ERROR[4]="SOPPA(CCSD) SETUP IN RESPONSE NOT CORRECT"

# Transition moments
CRIT1=`$GREP "\@ *STATE NO\: * 1 \*TRANSITION MOMENT\: (\-0| \-| 0|  )\.60797... * \*ENERGY\(eV\)\: * 10\.45913" $log | wc -l`
CRIT2=`$GREP "\@ *STATE NO\: * 2 \*TRANSITION MOMENT\: (\-0| \-| 0|  )\.53461... * \*ENERGY\(eV\)\: * 17\.46383" $log | wc -l`
CRIT3=`$GREP "\@ *STATE NO\: * 1 \*TRANSITION MOMENT\: (\-0| \-| 0|  )\.49698... * \*ENERGY\(eV\)\: * 12\.51509" $log | wc -l`
CRIT4=`$GREP "\@ *STATE NO\: * 2 \*TRANSITION MOMENT\: (\-0| \-| 0|  )\.90824... * \*ENERGY\(eV\)\: * 14\.44749" $log | wc -l`
CRIT5=`$GREP "\@ *STATE NO\: * 1 \*TRANSITION MOMENT\: (\-0| \-| 0|  )\.36132... * \*ENERGY\(eV\)\: *  7\.80268" $log | wc -l`
CRIT6=`$GREP "\@ *STATE NO\: * 2 \*TRANSITION MOMENT\: (\-0| \-| 0|  )\.34513... * \*ENERGY\(eV\)\: * 23\.07682" $log | wc -l`
TEST[5]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6`
CTRL[5]=6
ERROR[5]="TRANSITION MOMENTS NOT CORRECT"

# Sym 1 State 1
CRIT1=`$GREP "\@ *Excitation energy \: * (0| )\.384366" $log | wc -l`
CRIT2=`$GREP "\@ *Total energy \: * \-75\.641315" $log | wc -l`
CRIT2=1
CRIT3=`$GREP "\@ *SOPPA * p\-h * weight in excitation operator\: * 95\.20 \%" $log | wc -l`
CRIT4=`$GREP "\@ *SOPPA 2p\-2h weight in excitation operator\: * 4\.80 \%" $log | wc -l`
CRIT5=`$GREP "\@ *Oscillator strength \(LENGTH\) * \: * 9\.471.*(D|E)\-02" $log | wc -l`
CRIT6=`$GREP "Transition moment.* \-*0*\.6079" $log | wc -l`
TEST[6]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6`
CTRL[6]=6
ERROR[6]="STATE 1 (SYM 1) NOT CORRECT"

# Sym 1 State 2
CRIT1=`$GREP "\@ *Excitation energy \: * (0| )\.641784" $log | wc -l`
CRIT2=`$GREP "\@ *Total energy \: * \-75\.383897" $log | wc -l`
CRIT2=1
CRIT3=`$GREP "\@ *SOPPA * p\-h * weight in excitation operator\: * 95\.95 \%" $log | wc -l`
CRIT4=`$GREP "\@ *SOPPA 2p\-2h weight in excitation operator\: * 4\.05 \%" $log | wc -l`
CRIT5=`$GREP "\@ *Oscillator strength \(LENGTH\) * \: * (0| )\.1222" $log | wc -l`
CRIT6=`$GREP "Transition moment.* \-*0*\.5346" $log | wc -l`
TEST[7]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6`
CTRL[7]=6
ERROR[7]="STATE 2 (SYM 1) NOT CORRECT"

# Sym 2 State 1
CRIT1=`$GREP "\@ *Excitation energy \: * (0| )\.459921" $log | wc -l`
CRIT2=`$GREP "\@ *Total energy \: * \-75\.565760" $log | wc -l`
CRIT2=1
CRIT3=`$GREP "\@ *SOPPA * p\-h * weight in excitation operator\: * 95\.51 \%" $log | wc -l`
CRIT4=`$GREP "\@ *SOPPA 2p\-2h weight in excitation operator\: * 4\.49 \%" $log | wc -l`
CRIT5=`$GREP "\@ *Oscillator strength \(LENGTH\) * \: * 7\.5733.*(D|E)\-02" $log | wc -l`
CRIT6=`$GREP "Transition moment.* \-*0*\.4969" $log | wc -l`
TEST[8]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6`
CTRL[8]=6
ERROR[8]="STATE 1 (SYM 2) NOT CORRECT"

# Sym 2 State 2
CRIT1=`$GREP "\@ *Excitation energy \: * (0| )\.530935" $log | wc -l`
CRIT2=`$GREP "\@ *Total energy \: * \-75\.494746" $log | wc -l`
CRIT2=1
CRIT3=`$GREP "\@ *SOPPA * p\-h * weight in excitation operator\: * 96\.53 \%" $log | wc -l`
CRIT4=`$GREP "\@ *SOPPA 2p\-2h weight in excitation operator\: * 3\.47 \%" $log | wc -l`
CRIT5=`$GREP "\@ *Oscillator strength \(LENGTH\) * \: * (0| )\.2919" $log | wc -l`
CRIT6=`$GREP "Transition moment.* \-*0*\.9082" $log | wc -l`
TEST[9]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6`
CTRL[9]=6
ERROR[9]="STATE 2 (SYM 2) NOT CORRECT"

# Sym 3 State 1
CRIT1=`$GREP "\@ *Excitation energy \: * (0| )\.286743" $log | wc -l`
CRIT2=`$GREP "\@ *Total energy \: * \-75\.738938" $log | wc -l`
CRIT2=1
CRIT3=`$GREP "\@ *SOPPA * p\-h * weight in excitation operator\: * 95\.24 \%" $log | wc -l`
CRIT4=`$GREP "\@ *SOPPA 2p\-2h weight in excitation operator\: * 4\.76 \%" $log | wc -l`
CRIT5=`$GREP "\@ *Oscillator strength \(LENGTH\) * \: * 2\.495.*(D|E)\-02" $log | wc -l`
CRIT6=`$GREP "Transition moment.* \-*0*\.3613" $log | wc -l`
TEST[10]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6`
CTRL[10]=6
ERROR[10]="STATE 1 (SYM 3) NOT CORRECT"

# Sym 3 State 2
CRIT1=`$GREP "\@ *Excitation energy \: * (0| )\.848057" $log | wc -l`
CRIT2=`$GREP "\@ *Total energy \: * \-75\.177624" $log | wc -l`
CRIT2=1
CRIT3=`$GREP "\@ *SOPPA * p\-h * weight in excitation operator\: * 94\.66 \%" $log | wc -l`
CRIT4=`$GREP "\@ *SOPPA 2p\-2h weight in excitation operator\: * 5\.34 \%" $log | wc -l`
CRIT5=`$GREP "\@ *Oscillator strength \(LENGTH\) * \: * 6\.734.*(D|E)\-02" $log | wc -l`
CRIT6=`$GREP "Transition moment.* \-*0*\.3451" $log | wc -l`
TEST[11]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6`
CTRL[11]=6
ERROR[11]="STATE 2 (SYM 3) NOT CORRECT"

# Sym 4 State 1
CRIT1=`$GREP "\@ *Excitation energy \: * (0| )\.360673" $log | wc -l`
CRIT2=`$GREP "\@ *Total energy \: * \-75\.665008" $log | wc -l`
CRIT2=1
CRIT3=`$GREP "\@ *SOPPA * p\-h * weight in excitation operator\: * 95\.49 \%" $log | wc -l`
CRIT4=`$GREP "\@ *SOPPA 2p\-2h weight in excitation operator\: * 4\.51 \%" $log | wc -l`
TEST[12]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[12]=4
ERROR[12]="STATE 1 (SYM 4) NOT CORRECT"

# Sym 4 State 2
CRIT1=`$GREP "\@ *Excitation energy \: * (0| )\.784308" $log | wc -l`
CRIT2=`$GREP "\@ *Total energy \: * \-75\.241373" $log | wc -l`
CRIT2=1
CRIT3=`$GREP "\@ *SOPPA * p\-h * weight in excitation operator\: * 94\.96 \%" $log | wc -l`
CRIT4=`$GREP "\@ *SOPPA 2p\-2h weight in excitation operator\: * 5\.04 \%" $log | wc -l`
TEST[13]=`expr	$CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4`
CTRL[13]=4
ERROR[13]="STATE 2 (SYM 4) NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi
%EOF%
#######################################################################
